Skip to content

feat: Add Flex Query support with automatic query memory#16

Merged
NitayRabi merged 1 commit intomasterfrom
flex-queries
Nov 4, 2025
Merged

feat: Add Flex Query support with automatic query memory#16
NitayRabi merged 1 commit intomasterfrom
flex-queries

Conversation

@NitayRabi
Copy link
Copy Markdown
Contributor

Add comprehensive Flex Query Web Service integration to enable retrieval of account statements, trade confirmations, and historical data from Interactive Brokers. Flex Queries are automatically saved for easy reuse.

Features:

  • Execute Flex Queries with automatic retry and polling for results
  • Auto-save executed queries with friendly names from API responses
  • List all previously used Flex Queries
  • Forget/delete saved queries by ID or name
  • Optional XML parsing to JSON for easier data consumption
  • Persistent storage of query metadata in user's home directory

New Components:

  • FlexQueryClient: HTTP client for IB Flex Web Service API v3

    • sendRequest: Initiate query execution
    • getStatement: Retrieve query results with polling
    • executeQuery: High-level method combining both steps
    • parseStatement: Convert XML responses to JSON
  • FlexQueryStorage: Persistent storage manager for query metadata

    • JSON-based storage in ~/.interactive-brokers-mcp/flex-queries.json
    • CRUD operations for saved queries
    • Query lookup by ID, IB query ID, or friendly name
    • Automatic timestamp tracking (created, last used)

Configuration:

  • IB_FLEX_TOKEN: Environment variable for Flex Web Service token
  • Queries auto-saved on first execution with name from API
  • Optional friendly name override during execution

Testing:

  • 17 tests for FlexQueryClient covering all API interactions
  • 24 tests for FlexQueryStorage covering all storage operations
  • 10 additional tests for tool handlers covering Flex Query tools
  • All tests passing (120 passed, 1 skipped)

Documentation:

  • Updated README with Flex Query configuration instructions
  • Added links to IB documentation for setup
  • Documented all three new MCP tools

Breaking Changes: None - purely additive feature

Add comprehensive Flex Query Web Service integration to enable retrieval of
account statements, trade confirmations, and historical data from Interactive
Brokers. Flex Queries are automatically saved for easy reuse.

Features:
- Execute Flex Queries with automatic retry and polling for results
- Auto-save executed queries with friendly names from API responses
- List all previously used Flex Queries
- Forget/delete saved queries by ID or name
- Optional XML parsing to JSON for easier data consumption
- Persistent storage of query metadata in user's home directory

New Components:
- FlexQueryClient: HTTP client for IB Flex Web Service API v3
  * sendRequest: Initiate query execution
  * getStatement: Retrieve query results with polling
  * executeQuery: High-level method combining both steps
  * parseStatement: Convert XML responses to JSON

- FlexQueryStorage: Persistent storage manager for query metadata
  * JSON-based storage in ~/.interactive-brokers-mcp/flex-queries.json
  * CRUD operations for saved queries
  * Query lookup by ID, IB query ID, or friendly name
  * Automatic timestamp tracking (created, last used)

Configuration:
- IB_FLEX_TOKEN: Environment variable for Flex Web Service token
- Queries auto-saved on first execution with name from API
- Optional friendly name override during execution

Testing:
- 17 tests for FlexQueryClient covering all API interactions
- 24 tests for FlexQueryStorage covering all storage operations
- 10 additional tests for tool handlers covering Flex Query tools
- All tests passing (120 passed, 1 skipped)

Documentation:
- Updated README with Flex Query configuration instructions
- Added links to IB documentation for setup
- Documented all three new MCP tools

Breaking Changes: None - purely additive feature
@NitayRabi NitayRabi merged commit 594be95 into master Nov 4, 2025
1 check passed
@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 4, 2025

🎉 This PR is included in version 1.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant